package _3;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

class AP_Mt_Test {

    static void luan(int[] vb, int[] ve, int[] ep) {
        //把活动排列的顺序随机打乱，作为实际的申报顺序
        //vb ve 和 ep 的顺序随机调动
        int n = vb.length, t;
        int[] vb2=new int[n],ve2=new int[n],ep2=new int[n];
        Integer[] id = new Integer[n];
        for(int i=0; i<n; i++) {
            id[i] = i;
            vb2[i]=vb[i];
            ve2[i]=ve[i];
            ep2[i]=ep[i];
        }
        List<Integer> list = Arrays.asList(id);
        Collections.shuffle(list);
        list.toArray(id);
        for(int i=0; i<n; i++) {
            t = id[i];
            vb[i] = vb2[t];
            ve[i] = ve2[t];
            ep[i] = ep2[t];
        }
    }

    @Test
    void ApMt_test1() {

        int m,mep=1;//安排上2个活动, ep ~ expected results
        //用例1 输入vb1 ve1 ap1，输出 ap1 mep
        int [] vb1 = {30};
        int [] ve1 = {70};
        int [] ep1 = { 1};
        int [] ap1 = new int[vb1.length];
        //ap ~ anpai, ap[i]=0不安排, ap[i]=1安排

        luan(vb1,ve1,ep1);//打乱顺序
        m = AP_Mt.ApMt(vb1, ve1, ap1);
        assertEquals(mep,m);
        assertArrayEquals(ep1,ap1);

        int [] vb2 = {30,20,50, 70};
        int [] ve2 = {70,80,75,100};
        int [] ep2 = { 0, 1, 0,  0};
        int [] ap2 = new int[vb2.length];
        luan(vb2,ve2,ep2);
        m = AP_Mt.ApMt(vb2, ve2, ap2);
        assertEquals(mep,m);
        assertArrayEquals(ep2,ap2);
    }

    @Test
    void ApMt_test2() {

        int m,mep=2;
        int [] vb1 = {240, 450};
        int [] ve1 = {295, 520};
        int [] ep1 = {  1,   1};
        int [] ap1 = new int[vb1.length];
        luan(vb1,ve1,ep1);
        m = AP_Mt.ApMt(vb1, ve1, ap1);
        assertEquals(mep,m);
        assertArrayEquals(ep1,ap1);

        int [] vb2 = {240, 450, 250, 280, 460};
        int [] ve2 = {295, 520, 330, 400, 550};
        int [] ep2 = {  0,   0,   0,   1,   1};
        int [] ap2 = new int[vb2.length];
        luan(vb2,ve2,ep2);
        m = AP_Mt.ApMt(vb2, ve2, ap2);
        assertEquals(mep,m);
        assertArrayEquals(ep2,ap2);

        int [] vb3 = {240, 450, 250, 280, 460, 480};
        int [] ve3 = {295, 520, 330, 400, 550, 570};
        int [] ep3 = {  0,   0,   0,   1,   1,   0};
        int [] ap3 = new int[vb3.length];
        //luan(vb3,ve3,ep3);
        m = AP_Mt.ApMt(vb3, ve3, ap3);
        assertEquals(mep,m);
        assertArrayEquals(ep3,ap3);

    }

    @Test
    void ApMt_testn() {

        int m,mep=7;
        int [] vb1 = { 5, 46,115,180,400,600,750};
        int [] ve1 = {45,110,130,220,500,690,800};
        int [] ep1 = { 1,  1,  1,  1,  1,  1,  1};
        luan(vb1,ve1,ep1);
        int[] ap1 = new int[vb1.length];
        m = AP_Mt.ApMt(vb1, ve1, ap1);
        assertEquals(mep,m);
        assertArrayEquals(ep1,ap1);

        int [] vb2 = { 5, 46,115,180,400,600,750,   0, 10, 50,112,200,650,770,760};
        int [] ve2 = {45,110,130,220,500,690,800,  50, 65,120,150,230,730,810,839};
        int [] ep2 = { 1,  1,  0,  1,  1,  1,  0,   0,  0,  0,  1,  0,  0,  0,  1};
        //luan(vb2,ve2,ep2);
        int[] ap2 = new int[vb2.length];
        m = AP_Mt.ApMt(vb2, ve2, ap2);
        assertEquals(mep,m);
        assertArrayEquals(ep2,ap2);

    }
    @Test
    public void anpaiM_test2() {
        // 假设这是你的测试数据
        int[] vb = { /* 初始化数据 */ };
        int[] ve = { /* 初始化数据 */ };
        int[] ap = new int[vb.length];

        // 调用被测试的方法
        int result = AP_Mt.ApMt(vb, ve, ap);

        // 假设这是预期结果
        int[] expected = { /* 预期数组 */ };

        // 输出实际数组和预期数组的值
        System.out.println("Actual array: " + java.util.Arrays.toString(ap));
        System.out.println("Expected array: " + java.util.Arrays.toString(expected));

        // 进行断言
        assertArrayEquals(expected, ap);
    }
}